class U {
  //不能使用自带的构造方法
  //can't use the constructor method below
  constructor(e) {
    this.name = e;
  }
  transform;
  static create(e) {
    return Deno.core.ops.op_createGameObject(e);
  }
  addComponent(e) {
    let o = e.constructor;
    Deno.core.ops.op_addComponent(this.name, e, o.typeName);
  }
  getComponent(e) {
    return Deno.core.ops.op_getComponent(this.name, e.typeName);
  }
  getComponentById(e, o) {
    return Deno.core.ops.op_getComponentById(e, o);
  }
}
function j(t, e) {
  return Deno.core.ops.op_getComponentById(t, e);
}
globalThis.__GAMEOBJECT__ = new U("");
class S {
}
class x extends S {
  constructor(e, o) {
    super(), this.button = e, this.position = o;
  }
}
globalThis.__POST_MESSAGE__ = (t, e, ...o) => {
  switch (t) {
    case "keyboard": {
      let s = e;
      m.emit(t + s.state, new re(e.key));
      break;
    }
    case "mouse": {
      let s = e;
      m.emit(t + s.state, new x(e.button, e.position.toVec()));
      break;
    }
    case "mouse_move": {
      let s = e;
      m.emit(t + s.state, new x(e.button, e.position.toVec()));
      break;
    }
    case "ui": {
      let s = o[0][0].JsBind;
      j(s.objId, s.compId)[s.funcName]();
      break;
    }
    default:
      print(`type:${t},data:${JSON.stringify(e)}`);
  }
};
class L {
  constructor(e, o, s) {
    this.x = e, this.y = o, this.z = s;
  }
  into() {
    return [this.x, this.y, this.z];
  }
}
Object.defineProperty(Array.prototype, "x", {
  get: function() {
    return this[0];
  },
  set: function(t) {
    this[0] = t;
  }
});
Object.defineProperty(Array.prototype, "y", {
  get: function() {
    return this[1];
  },
  set: function(t) {
    this[1] = t;
  }
});
Object.defineProperty(Array.prototype, "z", {
  get: function() {
    return this[2];
  },
  set: function(t) {
    this[2] = t;
  }
});
Array.prototype.toVec = function() {
  return new L(this[0], this[1], this[2]);
};
const J = class {
  setTexture(e) {
  }
};
globalThis.__Material__ = new J();
const v = class {
};
globalThis.__Texture__ = new v();
const I = class {
  play() {
    return Deno.core.ops.opPlayAudio(this);
  }
  pause() {
    return Deno.core.ops.opPauseAudio(this);
  }
};
globalThis.__Audio__ = new I();
const V = class {
};
globalThis.__AudioClip__ = new V();
const $ = class {
};
globalThis.__Mesh__ = new $();
const E = class {
};
globalThis.__Scene__ = new E();
class a {
  static typeName = "Component";
  name;
  parent;
  _node;
  get node() {
    return this._node == null && (this._node = this.getGameObject(this.parent)), this._node;
  }
  onStart() {
  }
  onUpdate(e) {
  }
  getComponent(e) {
    return Deno.core.ops.op_getComponent(this.parent, e.typeName);
  }
  getGameObject(e) {
    return Deno.core.ops.op_getGameObject(this, e);
  }
  getUiNode(e) {
    return Deno.core.ops.opGetUiNode(e);
  }
  toString() {
    return "Component {}";
  }
}
globalThis.__Component__ = new a();
globalThis.__Components__ = [];
class N {
  constructor(e, o, s, n) {
    this.func = e, this.now = o, this.time = s, this.once = n, this.now += s;
  }
  addNextTime() {
    this.now += this.time;
  }
}
class z {
  callbacks = [];
  addCallback(e) {
    return this.callbacks.push(e) - 1;
  }
  checkCall(e) {
    for (const o in this.callbacks) {
      let s = this.callbacks[o];
      s?.now < e && (s.func(), s.once ? this.callbacks[o] = void 0 : s.addNextTime());
    }
    this.callbacks = this.callbacks.filter((o) => o);
  }
}
const T = new z();
globalThis.__Update__ = () => {
  T.checkCall(Date.now());
};
globalThis.setTimeout = (t, e) => {
  let o = new N(t, Date.now(), e, !0);
  T.addCallback(o);
};
globalThis.setInterval = (t, e) => {
  let o = new N(t, Date.now(), e, !1);
  T.addCallback(o);
};
const l = class extends a {
  setMaterial(e) {
    Deno.core.ops.opSetMaterial(this, e);
  }
};
l.typeName = "MaterialRender", globalThis.__MaterialRender__ = new l(), globalThis["##MaterialRender##"] = () => new l(), globalThis.__MaterialRender__ = new l();
let F = l;
const d = class extends a {
  setMesh(e) {
    Deno.core.ops.opSetMesh(this, e);
  }
};
d.typeName = "MeshRender", globalThis.__MeshRender__ = new d(), globalThis["##MeshRender##"] = () => new d(), globalThis.__MeshRender__ = new d();
const b = class extends a {
  get position() {
    return Deno.core.ops.opGetPosition(this).toVec();
  }
  setPosition(e) {
    return Deno.core.ops.opSetPosition(this, e.into());
  }
  get rotation() {
    return Deno.core.ops.opGetRotation(this).toVec();
  }
  setRotation(e) {
    return Deno.core.ops.opSetRotation(this, e.into());
  }
  get scale() {
    return Deno.core.ops.opGetScale(this).toVec();
  }
  setScale(e) {
    return Deno.core.ops.opSetScale(this, e.into());
  }
  translate(e) {
    return Deno.core.ops.opTranslate(this, e.into());
  }
  toString() {
    return `Transform { position:${JSON.stringify(this.position)}, rotation:${JSON.stringify(this.rotation)}, scale:${JSON.stringify(this.scale)}}`;
  }
};
b.typeName = "Transform", globalThis.__Transform__ = new b(), globalThis["##Transform##"] = () => new b(), globalThis.__Transform__ = new b();
const k = class {
};
globalThis.__Widget__ = new k();
let i = k;
const M = class extends i {
  static create() {
    return Deno.core.ops.opCreateButton();
  }
  get text() {
    return Deno.core.ops.opGetButtonText(this);
  }
  set text(e) {
    Deno.core.ops.opSetButtonText(this, e);
  }
};
globalThis.__Button__ = new M();
let H = M;
const q = class extends i {
};
globalThis.__Grid__ = new q();
const K = class extends i {
};
globalThis.__Image__ = new K();
const R = class extends i {
  static create() {
    return Deno.core.ops.opCreateLabel();
  }
  get text() {
    return Deno.core.ops.opGetLabelText(this);
  }
  set text(e) {
    Deno.core.ops.opSetLabelText(this, e);
  }
};
globalThis.__Label__ = new R();
let Q = R;
var G = /* @__PURE__ */ ((t) => (t[t.Row = 0] = "Row", t[t.Column = 1] = "Column", t[t.RowReverse = 2] = "RowReverse", t[t.ColumnReverse = 3] = "ColumnReverse", t))(G || {});
const W = class extends i {
  get orientation() {
    return Deno.core.ops.opGetPanelOrientation(this);
  }
  set orientation(e) {
    Deno.core.ops.opSetPanelOrientation(this, e);
  }
  get spacing() {
    return Deno.core.ops.opGetPanelSpacing(this);
  }
  set spacing(e) {
    Deno.core.ops.opSetPanelSpacing(this, e);
  }
};
globalThis.__Panel__ = new W();
const X = class extends i {
  static create() {
    return Deno.core.ops.opCreateTextBox();
  }
  get text() {
    return Deno.core.ops.opGetTextBoxText(this);
  }
  set text(e) {
    Deno.core.ops.opSetTextBoxText(this, e);
  }
  get placeholder() {
    return Deno.core.ops.opGetTextBoxHintText(this);
  }
  set placeholder(e) {
    Deno.core.ops.opSetTextBoxHintText(this, e);
  }
};
globalThis.__TextBox__ = new X();
const O = class {
  addChild(e) {
    Deno.core.ops.opAddChild(e);
  }
};
globalThis.__Canvas__ = new O();
let Z = O;
const Y = new Z(), P = class {
  play(e) {
    return Deno.core.ops.opPlayAudioClip(e);
  }
};
globalThis.__AudioEngine__ = new P();
let ee = P;
const te = new ee();
class oe {
  loadRes() {
  }
  loadMaterial(e) {
    return Deno.core.ops.opLoadMaterial(e);
  }
  loadTexture(e) {
  }
  loadMesh(e) {
    return Deno.core.ops.opLoadMesh(e);
  }
  loadJson(e) {
    let o = Deno.core.ops.opLoadJson(e);
    if (o)
      return JSON.parse(o);
  }
  loadAudio(e) {
    return Deno.core.ops.opLoadAudio(e);
  }
}
const g = new oe();
class se {
  /** 函数 function */
  func;
  /** 上下文 context */
  context;
  constructor(e, o) {
    this.func = e, this.context = o;
  }
}
class ne {
  _messageTable;
  constructor() {
    this._messageTable = /* @__PURE__ */ new Map();
  }
  /**
   * 开始监听项 
   * start listening item
   * @param eventType 监听类型 listen type
   * @param handler 监听函数 listen function 
   * @param context 监听上下文 listen context
   */
  on(e, o, s) {
    let n = this._messageTable.get(e);
    n || (n = [], this._messageTable.set(e, n)), this.has(e, o) || n.push(new se(o, s));
  }
  /**
   * 移除监听项
   * remove listening item
   * @param eventType 事件类型 event type
   * @param handler 事件函数 event function 
   */
  off(e, o) {
    let s = this._messageTable.get(e);
    if (s) {
      let n = s.findIndex((B) => B.func == o);
      n != -1 && s.splice(n, 1);
    }
  }
  /**
   * 触发该事件
   * trigger this event 
   * @param eventType 事件类型 event type
   * @param data 事件数据 event data
   */
  emit(e, ...o) {
    let s = this._messageTable.get(e);
    if (s)
      for (let n of s)
        n.func.call(n.context, ...o);
  }
  /**
   * 判断是否存在该类型的观察者
   * judge if the viewer of this type exist  
   * @param eventType 事件类型 event type 
   * @param handler 事件函数 event function 
   */
  has(e, o) {
    let s = this._messageTable.get(e);
    return s ? s.some((n) => n.func === o) : !1;
  }
}
class ae extends ne {
}
const m = new ae(), A = class {
  loadScene(e) {
    if (typeof e == "string")
      return Deno.core.ops.opLoadSceneFromName(e);
    if (typeof e == "object")
      return Deno.core.ops.opLoadScene(e), e;
  }
  preloadScene(e) {
    return Deno.core.ops.opPreloadScene(e);
  }
};
globalThis.__SceneManager__ = new A();
let ie = A;
const le = new ie();
function r(t) {
  t == null ? Deno.core.print(`null
`) : t.constructor == String ? Deno.core.print(t + `
`) : t instanceof a ? Deno.core.print(t.toString() + `
`) : Deno.core.print(JSON.stringify(t) + `
`);
}
globalThis.print = r;
class re extends S {
  constructor(e) {
    super(), this.key = e;
  }
}
const c = class c extends a {
  monkey;
  material0;
  material1;
  material_render;
  audio;
  isPlay = !1;
  button;
  onStart() {
    r(this.getGameObject("Monkey")), this.monkey = this.getGameObject("Monkey");
    let e = g.loadJson("hello.json");
    r(e), this.material_render = this.monkey.getComponent(F), this.material0 = g.loadMaterial("material/456.mtl"), this.material1 = g.loadMaterial("material/123.mtl");
    let o = g.loadAudio("audio/music.mp3");
    r(o), this.audio = te.play(o), r(this.audio), setTimeout(() => {
      le.loadScene("scene/main2.scene");
    }, 3e3);
  }
  time = 0;
  is0 = !1;
  onUpdate(e) {
    let o = this.monkey.transform.rotation;
    o.y += 1, this.monkey.transform.setRotation(o), this.time += e;
  }
};
c.typeName = "Comp", globalThis.__Comp__ = new c(), globalThis["##Comp##"] = () => new c(), globalThis.__Components__.push({ name: "Comp", script: "main.ts" });
let w = c;
const p = class p extends a {
  button;
  label;
  onStart() {
    this.button = this.getUiNode("Hello"), print(this.button), print(this.button.text), this.button.text = "hello world", print(this.button.text), this.label = this.getUiNode("Label"), print(this.label), print(this.label.text), this.label.text = "hello world", print(this.label.text);
  }
};
p.typeName = "UiTest", globalThis.__UiTest__ = new p(), globalThis["##UiTest##"] = () => new p(), globalThis.__Components__.push({ name: "UiTest", script: "ui_test.ts" });
let y = p;
const h = class h extends a {
  button;
  label;
  onStart() {
    this.button = H.create(), this.button.text = "TestAddChild";
    let e = Q.create();
    e.text = "TestAddChild", Y.addChild(e);
  }
};
h.typeName = "UiTest1", globalThis.__UiTest1__ = new h(), globalThis["##UiTest1##"] = () => new h(), globalThis.__Components__.push({ name: "UiTest1", script: "ui_test1.ts" });
let f = h;
const _ = class _ extends a {
  button;
  label;
  onStart() {
    let e = this.getUiNode("Panel");
    print(e.orientation), e.orientation = G.Column, print(e.spacing), e.spacing = 50;
  }
};
_.typeName = "UiTest2", globalThis.__UiTest2__ = new _(), globalThis["##UiTest2##"] = () => new _(), globalThis.__Components__.push({ name: "UiTest2", script: "ui_test2.ts" });
let D = _;
const u = class u extends a {
  onStart() {
    let e = this.getUiNode("TextBox");
    e.placeholder = "请输入文本", print(e.text), setTimeout(() => {
      print(e.text);
    }, 5e3);
  }
  btnClicked() {
    print("hello world");
  }
};
u.typeName = "UiTest3", globalThis.__UiTest3__ = new u(), globalThis["##UiTest3##"] = () => new u(), globalThis.__Components__.push({ name: "UiTest3", script: "ui_test3.ts" });
let C = u;
